﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vit.Database.Schema
{
    [Serializable]
    public class ForeignKeySchema : SchemaObjectBase
    {
        public ForeignKeySchema()
        {
            KeyColumns = new List<ForeignKeyColumnSchema>();
        }

        public string PrimaryTableName { get; set; }
        public string ForeignTableName { get; set; }

        private TableSchema primaryTable = null;
        public TableSchema PrimaryTable
        {
            get
            {
                if (primaryTable == null)
                {
                    primaryTable = this.Schema.Tables.First(o => string.Equals(o.Name, this.PrimaryTableName, StringComparison.OrdinalIgnoreCase));
                }
                return primaryTable;
            }
        }
        private TableSchema foreignTable = null;
        public TableSchema ForeignTable
        {
            get
            {
                if (foreignTable == null)
                {
                    foreignTable = this.Schema.Tables.First(o => string.Equals(o.Name, this.ForeignTableName, StringComparison.OrdinalIgnoreCase));
                }
                return foreignTable;
            }
        }

        public List<ForeignKeyColumnSchema> KeyColumns { get; set; }
    }
}
